package p.sunmes.les.data;

import java.io.Serializable;

public class Data implements Serializable {

	private static final long serialVersionUID = -5617937615193500270L;

	private float num;
	private float off;

	public Data() {
		this(0);
	}

	public Data(float dt) {
		setValue(dt);
		updateOff();
	}

	public float getValue() {
		return num + off;
	}

	public int getIntValue() {
		return (int) getValue();
	}

	public void setValue(float dt) {
		num = dt - off;
	}

	public void setUpdate(float dt) {
		setValue(dt);
		updateOff();
	}

	public void decreaseValue(float dt) {
		if (dt < 0) {
			return;
		}
		num -= dt;
	}

	public void increaseValue(float dt) {
		if (dt < 0) {
			return;
		}
		num += dt;
	}

	public void updateOff() {
		float o = (float) (Math.random() * 10000) - 5000;
		if (o == 0) {
			o = 10000;
		}
		num = num + off - o;
		off = o;
	}

	@Override
	public String toString() {
		return String.format("Data{Hash[%d],Value[%f]}", hashCode(),
				getValue());
	}
}
